package com.loper7.base.utils.img;

import java.io.IOException;
import java.io.InputStream;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;

public class GetResourceImage {

	public static Bitmap get(Context context,int resId){
		
		BitmapFactory.Options opt = new BitmapFactory.Options();

		opt.inPreferredConfig = Bitmap.Config.RGB_565;

		opt.inPurgeable = true;

		opt.inInputShareable = true;

		//获取资源图片
		InputStream is = context.getResources().openRawResource(resId);
		
		Bitmap bitmap = null;
		
		bitmap = BitmapFactory.decodeStream(is,null, opt);
		
		try {
			is.close();
		} catch (IOException e) {
		}
		return bitmap;
	}
	public static Drawable getDrawable(Context context,int resId){
		BitmapFactory.Options opt = new BitmapFactory.Options();

		opt.inPreferredConfig = Bitmap.Config.RGB_565;

		opt.inPurgeable = true;

		opt.inInputShareable = true;

		//获取资源图片
		InputStream is = context.getResources().openRawResource(resId);
		
		Drawable drawable = Drawable.createFromStream(is, "src");
		
		try {
			is.close();
		} catch (IOException e) {
		}
		return drawable;
	
	}
}
